package at.ttasat;

import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.ObjectInputStream;

public class CreateCNFFile {

	public static void main(String[] args) throws Exception {
		if(args.length == 0) {
			System.out.println("CreateCNFFile <resultFile> <seed> <cnfFileToCreate>");
			return;
		}
		FileInputStream inputStream = new FileInputStream(args[0]);
		ObjectInputStream objectInputStream = new ObjectInputStream(inputStream);
		SolverTestResult result = (SolverTestResult) objectInputStream.readObject();
		objectInputStream.close();
		write(result.getMaximalVariables(), result.getMaximalClauses(), result.getWeightingFactor(), Long.valueOf(args[1]), args[2]);
	}

	private static void write(int maximalVariables, int maximalClauses, double weightingFactor, long seed, String fileName) throws IOException {
		RunDescription runDescription = new RunDescription(seed, maximalVariables, maximalClauses, weightingFactor);
		String dimacsString = runDescription.getDimacsString();
		FileWriter writer = new FileWriter(fileName);
		writer.write(dimacsString);
		writer.close();
	}
}
